package com.whisperarts.financer.app.dialogs;

import org.eclipse.swt.widgets.Shell;

import com.whisperarts.financer.model.transaction.Category;

public class EditCategoryDialog extends AddCategoryDialog {
	private final Category category;

	public EditCategoryDialog(Shell parentShell, Category category) {
		super(parentShell);
		this.category = category;
	}

	@Override
	protected void fillData() {
		textName.setText(category.getName());		
		comboCategories.select(adapter.getCategoryPosition(adapter.getCategoryById(category.getParentId())));
		button.setIncome(category.isIncome());
	}
	
	@Override
	protected Category getExcludeCategory() {
		return category;
	}
	
	@Override
	protected boolean isNameExists(String name) {
		if (!category.getName().equals(name)) {
			return super.isNameExists(name);
		}
		return false;
	}

	@Override
	protected Category getCategoryToCreate() {
		return this.category;
	}
	
}
